<template>
    <div class="app-container">
        <div class="block">
            <el-row :gutter="20">

                <el-col :span="4">

                            <el-select v-model="listQuery.criteria.goodsType" placeholder="选择商品类型" size="mini">
                                <el-option label="全部"
                                    value="">
                                </el-option>
                                <el-option v-for="item in goodsTypeList" :key="item.id" :label="item.name"
                                    :value="item.num">
                                </el-option>
                            </el-select>


                    </el-col>

                <el-col :span="4">
                    <el-input v-model="listQuery.criteria.goodsName" placeholder="商品名称"
                        size="mini"></el-input>
                </el-col>
                <el-col :span="4">
                    <el-input v-model="listQuery.criteria.supplierName" placeholder="供应商"
                        size="mini"></el-input>
                </el-col>

                <el-col :span="4">
                    <el-input v-model="listQuery.criteria.storeHouseName" placeholder="仓库名称"
                        size="mini"></el-input>
                </el-col>

                <el-col :span="12" style="margin-top: 10px;">
                    <el-button type="success" icon="el-icon-search" @click.native="search" size="mini">搜索</el-button>
                    <el-button type="primary" icon="el-icon-refresh" @click.native="reset" size="mini">重置</el-button>
                </el-col>
            </el-row>
        </div>

        <el-row>
      <el-col :span="20">
        <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}"
          @current-change="handleCurrentChange">


          <el-table-column label="配图" align="center" :span="2">
              <template slot-scope="scope">
                <img :src="`${baseUrl}file/getFileByGoodsId/${scope.row.goodsId}?${generNum()}`" alt="加载失败" class="avatar"
                  style="max-height: 50px;max-width: 120px;">
              </template>

            </el-table-column>
            <el-table-column label="商品名称" align="center" :span="4">
              <template slot-scope="scope">
                <span>{{ scope.row.goodsName }}</span>
              </template>
            </el-table-column>

            <el-table-column label="进价" align="center" :span="4">
              <template slot-scope="scope">
                <span>{{ scope.row.price / 100 }}元/{{ scope.row.priceUnit }}</span>
              </template>
            </el-table-column>

            <el-table-column label="售价" align="center" :span="4">
              <template slot-scope="scope">
                <span>{{ scope.row.salePrice / 100 }}元/{{ scope.row.priceUnit }}</span>
              </template>
            </el-table-column>
            <el-table-column label="商品类型" align="center" :span="4">
              <template slot-scope="scope">
                <span>{{ getTypeValueDict(scope.row.goodsType) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="商品规格" align="center" :span="4">
              <template slot-scope="scope">
                <el-tag :key="tag" v-for="tag in scope.row.specification" size="mini">
                  {{ tag }}
                </el-tag>
              </template>
            </el-table-column>

            <el-table-column label="供应商" align="center">
                <template slot-scope="scope">
                  {{ scope.row.supplierName }}
                </template>
            </el-table-column>

            <el-table-column label="所在仓库" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.storeHouseName }}</span>
              </template>
            </el-table-column>

            <el-table-column label="库存" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.storeNum }}</span>
              </template>
            </el-table-column>

            <el-table-column label="单位容量" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.capacity }}</span>
              </template>
            </el-table-column>

            <el-table-column label="状态" align="center">
                <template slot-scope="scope">
                    <el-tag  v-if="scope.row.status==1">下架</el-tag>
                    <el-tag type="success" v-if="scope.row.status==0">上架</el-tag>
                </template>

            </el-table-column>



          <el-table-column label="操作" min-width="60px" :span="5">
            <template slot-scope="scope">
                <el-button v-if="scope.row.status==1" type="primary" size="mini" @click.native="putGoods(scope.row)">上架</el-button>
                <el-button v-if="scope.row.status==0" type="danger" size="mini" @click.native="downGoods(scope.row.id)">下架</el-button>
            </template>

          </el-table-column>




        </el-table>

        <el-pagination background layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 50, 100, 500]"
          :page-size="listQuery.size" :total="total" :current-page.sync="listQuery.current" @size-change="changeSize"
          @current-change="fetchPage" @prev-click="fetchPrev" @next-click="fetchNext">
        </el-pagination>

      </el-col>
    </el-row>


<el-dialog title="商品上架" :visible.sync="formVisible" width="50%" >
    <el-form :model="form" ref="form" label-width="100px" class="demo-ruleForm">
  <el-form-item
    label="售价"
    prop="salePrice"
    :rules="[
      { required: true, message: '售价不能为空'},
      { type: 'number', message: '售价必须为数字值'}
    ]"
  >
    <el-input v-model.number="form.salePrice" autocomplete="off" ></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click.native="submitForm('form')">提交</el-button>
    <el-button  @click.native="formVisible=false">取消</el-button>
  </el-form-item>
</el-form>

    </el-dialog>



    </div>
</template>

<script src="./shelves.js">
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>
